Telegram Group & Telegram Channel
Какие проблемы могут возникнуть при использовании synchronized, и как их решать?

1️⃣ Блокировки (Blocking)

— Потоки, ожидающие освобождения блокировки, простаивают, что снижает производительность.
Решение: использовать ReentrantLock, который позволяет гибко управлять блокировками, включая таймауты и прерывания.

2️⃣ Взаимная блокировка (Deadlock)

— Возникает, когда два потока блокируют друг друга, ожидая освобождения ресурсов.
— Решение: явный порядок блокировки, использование tryLock() с таймаутом

3️⃣ Отсутствие гибкости

— Synchronized не дает возможности проверки состояния блокировки.
— Решение: Использовать Lock, который позволяет проверить, занята ли блокировка (isLocked()) и настроить приоритет выполнения.

4️⃣ Проблема ложного пробуждения (Spurious Wakeup)

— Поток может быть пробужден без явного вызова notify().
— Решение: всегда использовать while, а не if при ожидании wait().
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/java_interview_lib/810
Create:
Last Update:

Какие проблемы могут возникнуть при использовании synchronized, и как их решать?

1️⃣ Блокировки (Blocking)

— Потоки, ожидающие освобождения блокировки, простаивают, что снижает производительность.
Решение: использовать ReentrantLock, который позволяет гибко управлять блокировками, включая таймауты и прерывания.

2️⃣ Взаимная блокировка (Deadlock)

— Возникает, когда два потока блокируют друг друга, ожидая освобождения ресурсов.
— Решение: явный порядок блокировки, использование tryLock() с таймаутом

3️⃣ Отсутствие гибкости

— Synchronized не дает возможности проверки состояния блокировки.
— Решение: Использовать Lock, который позволяет проверить, занята ли блокировка (isLocked()) и настроить приоритет выполнения.

4️⃣ Проблема ложного пробуждения (Spurious Wakeup)

— Поток может быть пробужден без явного вызова notify().
— Решение: всегда использовать while, а не if при ожидании wait().

BY Библиотека собеса по Java | вопросы с собеседований


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/java_interview_lib/810

View MORE
Open in Telegram


Библиотека собеса по Java | вопросы с собеседований Telegram | DID YOU KNOW?

Date: |

Should I buy bitcoin?

“To the extent it is used I fear it’s often for illicit finance. It’s an extremely inefficient way of conducting transactions, and the amount of energy that’s consumed in processing those transactions is staggering,” the former Fed chairwoman said. Yellen’s comments have been cited as a reason for bitcoin’s recent losses. However, Yellen’s assessment of bitcoin as a inefficient medium of exchange is an important point and one that has already been raised in the past by bitcoin bulls. Using a volatile asset in exchange for goods and services makes little sense if the asset can tumble 10% in a day, or surge 80% over the course of a two months as bitcoin has done in 2021, critics argue. To put a finer point on it, over the past 12 months bitcoin has registered 8 corrections, defined as a decline from a recent peak of at least 10% but not more than 20%, and two bear markets, which are defined as falls of 20% or more, according to Dow Jones Market Data.

Spiking bond yields driving sharp losses in tech stocks

A spike in interest rates since the start of the year has accelerated a rotation out of high-growth technology stocks and into value stocks poised to benefit from a reopening of the economy. The Nasdaq has fallen more than 10% over the past month as the Dow has soared to record highs, with a spike in the 10-year US Treasury yield acting as the main catalyst. It recently surged to a cycle high of more than 1.60% after starting the year below 1%. But according to Jim Paulsen, the Leuthold Group's chief investment strategist, rising interest rates do not represent a long-term threat to the stock market. Paulsen expects the 10-year yield to cross 2% by the end of the year. A spike in interest rates and its impact on the stock market depends on the economic backdrop, according to Paulsen. Rising interest rates amid a strengthening economy "may prove no challenge at all for stocks," Paulsen said.

Библиотека собеса по Java | вопросы с собеседований from ms


Telegram Библиотека собеса по Java | вопросы с собеседований
FROM USA